#region Using References

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

#endregion

namespace Beaker.Services.Tasks
{
	public interface ITaskService
	{
		/// <summary>
		/// Start the given task
		/// </summary>
		/// <param name="action">The action executing the task</param>
		/// <returns>The task started</returns>
		Task Execute( Action action );

		/// <summary>
		/// Starts the given task and expects a result
		/// </summary>
		/// <typeparam name="T">The type of the result</typeparam>
		/// <param name="func">The function executing the task and returning the result</param>
		/// <returns></returns>
		Task<T> Execute<T>( Func<T> func );

		/// <summary>
		/// Starts the given task and observes the enumerable result one-at-a-time asynchronously
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="func">The func that returns the enumerable</param>
		/// <returns>An observable with the results</returns>
		/// <remarks>Only works when the IEnumerable uses deferred execution (linq)</remarks>
		IObservable<T> Observe<T>( Func<IEnumerable<T>> func );

		/// Creates a collection that will group multiple tasks together
		/// </summary>
		/// <typeparam name="T">The type of the results that the takss in the colletoin will return</typeparam>
		/// <returns>The collection to add tasks on</returns>
		ITaskCollection<T> CreateCollection<T>();
	}
}